home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-03 | 6.9 KB | 279 lines | [TEXT/ttxt] |
- --<<<
- class GenericButton (Actuator,TwoDPresenter)
- instance vars
- activateAction
- authorData:(undefined)
- _enabled
- pressAction:(undefined)
- releaseAction:(undefined)
- end
-
- method init self { class GenericButton } #rest args #key\
- enabled: (true) \
- activateAction:(undefined) ->
- (
- apply nextMethod self args
- self._enabled := enabled
- self.authorData := undefined
- self.activateAction := activateAction
- self
- )
-
- method press self {class GenericButton} -> (
- if (self.enabled) do (
- if (self.pressAction != undefined) do
- self.pressAction self.authorData self
- notifyChanged self false
- )
- nextMethod self
- )
-
- method activate self {class GenericButton} -> (
- if (self.enabled) do (
- if (self.activateAction != undefined) do
- self.activateAction self.authorData self
- notifyChanged self false
- )
- nextMethod self
- )
-
- method release self {class GenericButton} -> (
- if (self.enabled) do (
- if (self.releaseAction != undefined) do
- self.releaseAction self.authorData self
- notifyChanged self false
- )
- nextMethod self
- )
-
- method multiactivate self {class GenericButton} n -> (
- if (self.enabled) do (
- activate self
- notifyChanged self false
- )
- nextMethod self n
- )
-
- method toggleOn self {class GenericButton} ->
- (
- if (not self.toggledOn) do (
- NotifyChanged self false
- NextMethod self
- )
- )
-
- method toggleOff self {class GenericButton} ->
- (
- if (self.toggledOn) do (
- NotifyChanged self false
- NextMethod self
- )
- )
-
- method enabledGetter self {class GenericButton} -> (
- return self._enabled
- )
-
- method enabledSetter self {class GenericButton} enabled -> (
- if (enabled != self._enabled) do (
- self._enabled := enabled
- notifyChanged self false
- )
- enabled
- )
-
- class StencilButton (GenericButton)
- class variables
- BorderWidth:2
- instance variables
- recessedFrame:(new Frame)
- buttonFrame:(new Frame scheme:theButtonScheme)
- stencilTransform:(mutableCopy identityMatrix)
- _stencil
- border:(new Rect)
- end
-
- method init self { class StencilButton } #rest args #key \
- stencil:(new Rect x2:10 y2:10) \
- boundary: ->
- (
- if (boundary = unsupplied) do ( \
- local inset := (StencilButton.BorderWidth*2 + 2)*2
- if (stencil = undefined) then
- boundary := new rect x2:(10+inset) y2:(10+inset)
- else
- boundary := new rect x2:(stencil.width+inset) \
- y2:(stencil.height+inset)
- )
- apply nextMethod self boundary:boundary stationary:true args
- self._stencil := stencil
- )
-
- method recalcRegion self {class StencilButton} ->
- (
- nextMethod self
- SetBoundary self.recessedFrame self.boundary
- local border := self.border
- SetTo border self.boundary
- local width := StencilButton.BorderWidth + 1
- InsetRect border width width @mutate
- SetBoundary self.buttonFrame border
- InsetRect border -1 -1 @mutate
- if (self._stencil != undefined) do (
- SetTo self.stencilTransform self.globalTransform
- Translate self.stencilTransform self.bbox.x1 self.bbox.y1
- local xOffset := (self.boundary.width - self._stencil.width)/2
- local yOffset := (self.boundary.height - self._stencil.height)/2
- translate self.stencilTransform xOffset yOffset
- )
- )
-
- method draw self {class StencilButton} surf clip ->
- (
- local transform := self.globalTransform
- fill surf self.globalBoundary clip identityMatrix ColorScheme.grayBrushes[5]
- local drawLowered := self.pressed or self.toggledOn
- if (drawLowered) then
- drawLoweredFrame self.buttonFrame surf clip transform
- else
- drawRaisedFrame self.buttonFrame surf clip transform
- drawLoweredFrame self.recessedFrame surf clip transform
- stroke surf self.border clip transform ColorScheme.grayBrushes[2]
- if (self._stencil != undefined) do (
- transform := self.stencilTransform
- if (drawLowered) do
- translate transform 1 1
- fill surf self._stencil clip transform blackBrush
- if (drawLowered) do
- translate transform -1 -1
- )
- if (not self._enabled) do
- fill surf self.boundary clip self.globalTransform ColorScheme.disableBrush
- NextMethod self surf clip
- )
-
- method stencilGetter self {class StencilButton} -> self._stencil
- method stencilSetter self {class StencilButton} newStencil ->
- (
- self._stencil := newStencil
- notifyChanged self true
- newStencil
- )
-
- class TextButton(StencilButton)
- instance variables
- _font
- _text
- textTransform:(mutableCopy identityMatrix)
- end
-
- method init self { class TextButton } #rest args #key \
- text:("Hello") \
- font:(theSystemFont) \
- stencil:(undefined) \
- boundary: ->
- (
- if (not (isAKindOf text String)) do
- text := text as String
- local tStencil := new TextStencil font:font.font \
- size:font.fontSize string:text
- if (boundary = unsupplied) do (
- local stencilWidth,stencilHeight
- if (stencil = undefined) then (
- stencilWidth := 0
- stencilHeight := 0
- )
- else (
- stencilWidth := stencil.width
- stencilHeight := stencil.height
- )
- local frameSpan := (StencilButton.BorderWidth*2 + 1)*2
- local xinset := tStencil.width + frameSpan + 2 + stencilWidth
- local yInset := font.leading + frameSpan + stencilHeight
- boundary := new Rect x2:xInset y2:yInset
- )
- apply nextMethod self boundary:boundary stencil:stencil args
- self._text := tStencil
- self._font := font
- )
-
- method recalcRegion self {class TextButton} ->
- (
- nextMethod self
- local tStencil := self._text
- if (tStencil != undefined) do (
- local textTrans := self.textTransform
- SetTo textTrans self.globalTransform
- local xOffset := (self.boundary.width - tStencil.width)/2
- translate textTrans xOffset \
- (self.border.y2 - (self._font.descent + 2))
- local stencil := self._stencil
- if (stencil != undefined) do (
- local stencilTrans := self.stencilTransform
- local textTop := textTrans.ty - self._font.leading
- local stencilHeight := stencil.height
- if ((stencilTrans.ty + stencilHeight) > textTop) do (
- stencilTrans.ty := textTop - stencilHeight
- )
- )
- )
- )
-
- method draw self {class TextButton} surface clip ->
- (
- NextMethod self surface clip
- local drawLowered := self.pressed or self.toggledOn
- local tStencil := self._text
- if (tStencil != undefined) do (
- local transform := self.textTransform
- if (drawLowered) do
- translate transform 1 1
- Fill surface tStencil clip transform blackBrush
- if (drawLowered) do
- translate transform -1 -1
- if (not self._enabled) do
- fill surface self.boundary clip self.globalTransform \
- ColorScheme.disableBrush
- )
- )
-
- method textGetter self {class TextButton} ->
- (
- local tStencil := self._text
- if (tStencil != undefined) then
- tStencil.string
- else
- undefined
- )
-
- method textSetter self {class TextButton} newString ->
- (
- if (self._text = undefined) then
- self._text := new TextStencil string:newString \
- font:self._font.font fontSize:self._font.fontSize
- else
- self._text.string := newString
- notifyChanged self true
- newString
- )
-
- method fontGetter self {class TextButton} ->
- (
- self._font
- )
-
- method fontSetter self {class TextButton} newFont ->
- (
- local tStencil := self._text
- if (tStencil != undefined) do (
- tStencil.font := newFont.font
- tStencil.size := newFont.fontSize
- translate self.textTransform 0 \
- (newFont.leading - self._font.leading)
- notifyChanged self true
- )
- self._font := newFont
- )
-
- -->>>
-